#ifndef REQUESTS_H
#define REQUESTS_H
#include <QObject>
#include "tools.h"
#include "json/json.h"
class Satory;
class BaseRequest: public QObject
{
    Q_OBJECT
   protected:
    Satory* Master;
    Json::Value root;
public:
    BaseRequest(Satory* master);
    Json::Value& Get(){return root;}
    virtual void OnError(Json::Value& error)=0;
    virtual void OnAnswer(Json::Value& answer)=0;
};
enum RequestTypes{
    TRegisterRequest,
    TLoginRequest,
    TResetKeyRequest,
    TPublicKeyGetRequest,
    TPrivateKeyGetRequest,
    TVerifyRequest,
    TAskAuthRequest,
    TConfirmAuthRequest,
    TDeleteAuthRequest,
    TSendMessageRequest,
    TMessageMarkReadRequest,
    THistoryGetRequest,
    TChatKeyGetRequest,
    TUserProfileGetRequest};
class RegisterRequest:public BaseRequest
{
    std::string mPrivateKey;
    public:
    RegisterRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
    void SetKey(const std::string& key);
};
class LoginRequest:public BaseRequest
{
    public:
    LoginRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
};
class ResetKeyRequest:public BaseRequest
{
    std::string mPrivateKey;
    public:
    ResetKeyRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
    void SetKey(const std::string& key);
};
class PublicKeyGetRequest:public BaseRequest
{
    Q_OBJECT
    public:
    PublicKeyGetRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
signals:
    void KeyArrived(BaseRequest* request,Json::Value& answer);
};
class PrivateKeyGetRequest:public BaseRequest
{
    public:
    PrivateKeyGetRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
};
class VerifyRequest:public BaseRequest
{
    public:
    VerifyRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
};
class AskAuthRequest:public BaseRequest
{
    public:
    AskAuthRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
};
class ConfirmAuthRequest:public BaseRequest
{
    public:
    ConfirmAuthRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
};
class DeleteAuthRequest:public BaseRequest
{
    public:
    DeleteAuthRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error){};
    virtual void OnAnswer(Json::Value& answer){};
};
class SendMessageRequest:public BaseRequest
{
    public:
    SendMessageRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
};
class MessageMarkReadRequest:public BaseRequest
{
    public:
    MessageMarkReadRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error){};
    virtual void OnAnswer(Json::Value& answer){};
};
class HistoryGetRequest:public BaseRequest
{
    public:
    HistoryGetRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error){};
    virtual void OnAnswer(Json::Value& answer){};
};
class ChatKeyGetRequest:public BaseRequest
{
    Q_OBJECT
    public:
     ChatKeyGetRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error);
    virtual void OnAnswer(Json::Value& answer);
    signals:
        void KeyArrived(BaseRequest* request,Json::Value& answer);
};

class UserProfileGetRequest:public BaseRequest
{
    public:
    UserProfileGetRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error){};
    virtual void OnAnswer(Json::Value& answer){};
};
class UserUpdateProfileRequest:public BaseRequest
{
    public:
    UserUpdateProfileRequest(Satory* master):BaseRequest(master){}
    virtual void OnError(Json::Value& error){};
    virtual void OnAnswer(Json::Value& answer){};
};



#endif // REQUESTS_H
